import { DISPLAY_TYPE_ENUM, DISPLAY_TYPE_IMAGE } from '@/components/Custom/CommonList/Constant'
import { CHANNEL_STATUS_MAP } from '../../../utils/utils'

export default {
  data() {
    return {
      orderAuditDialogVisible: false,
      ids: [],
      listConfig: {
        selectType: 'selection', // // 多选selection／单选index，如果不需要，不设置
        selectable: (row) => {
          if ([30, 40].includes(Number(row.status))) {
            return false // 不可勾选
          } else {
            return true // 可勾选
          }
        },
        columns: [
          {
            prop: 'goodsOptCode',
            label: '渠道选货单号'
          },
          {
            prop: 'submitTime',
            label: '提交时间'
          },
          {
            prop: 'operator',
            label: '操作人'
          },
          {
            prop: 'totalNumber',
            label: '总件数'
          },
          {
            prop: 'totalAmount',
            label: '订单金额',
            prefix: '￥'
          },
          {
            prop: 'fromChannel',
            label: '源渠道'
          },
          {
            prop: 'toChannel',
            label: '目标渠道',
            type: DISPLAY_TYPE_IMAGE
          },
          {
            prop: 'status',
            label: '审核状态',
            type: DISPLAY_TYPE_ENUM,
            enumMap: CHANNEL_STATUS_MAP
          }
        ],
        opts: {
          width: 200,
          lines: 2,
          custom: [
            {
              text: '查看订单',
              size: 'small',
              emit: 'go-detail'
            },
            {
              text: '审核记录',
              size: 'small',
              emit: 'show-record-dialog'
            },
            {
              text: '渠道定价',
              size: 'small',
              emit: 'go-price',
              availability: (rowItem) => {
                // console.log('availability==', rowItem.goodsOptCode)
                return [30, 40].includes(Number(rowItem.status))
              }
            },
            {
              text: '订单审核',
              size: 'small',
              emit: 'show-order-audit-dialog',
              availability: (rowItem) => {
                return [20, 30, 40].includes(Number(rowItem.status))
              }
            }
          ]
        }
      }
    }
  },
  methods: {
    onSelectedChange(val) { // 回调获取已选中的ids
      const ids = val.map(item => item.goodsOptCode)
      this.ids = ids
    },
    detail(row) { // 跳转详情
      this.$router.push({
        path: '/orders/channel/detail',
        query: { id: row.id }
      })
    },
    price(row) { // 跳转定价
      this.$router.push({
        path: '/orders/channel/price',
        query: { id: row.id }
      })
    },
    showOrderAuditDialog() {
      this.orderAuditDialogVisible = true
    }
  }
}
